package so.sao.code.service.web.api;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import so.sao.code.dto.request.ThirdPartyCodeCreate;
import so.sao.code.dto.response.ThirdPartyCodeDto;
import so.sao.code.service.service.TagBatchLookupTableService;
import so.sao.sso.bind.CurrentUser;
import so.sao.sso.feign.dto.UserDTO;
import so.sao.top.core.util.exceptions.ServiceException;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "thirdPartyCode", value = "第三方码生成控制器")
@RestController
@RequestMapping("/api/thirdPartyCode")
public class ThirdPartyCodeController {
	
	@Autowired
	TagBatchLookupTableService tagBatchLookupTableService;
	
	
	@ApiOperation(value = "获取码段", notes = "通过码数量获取码段")
	@PostMapping(value = "createCodeSegment",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity<ThirdPartyCodeDto> createCodeSegment(@ApiIgnore @CurrentUser UserDTO user,
			@Valid @RequestBody ThirdPartyCodeCreate thirdPartyCodeCreate) throws ServiceException,Exception{
		Long eseId= user.getEseId();
		return new ResponseEntity<>(tagBatchLookupTableService.createCodeSegment(thirdPartyCodeCreate,eseId), HttpStatus.CREATED);
	}
}
